package org.jeecg.modules.quartz.job;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.util.DateUtils;
import org.jeecg.modules.demo.stock.entity.TbStockCode;
import org.jeecg.modules.demo.stock.service.ITbStockCodeService;
import org.jeecg.modules.demo.stock.service.ITbStockKService;
import org.jeecg.modules.demo.stock.service.ITbStockMinuteService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;

/**
 * 示例不带参定时任务
 * 
 * @Author Scott
 */
@Slf4j
@Service
public class SampleJob implements Job {

	//股票k线
	@Autowired
	private ITbStockKService tbStockKService;
	//股票分钟交易
	@Autowired
	private ITbStockMinuteService tbStockMinuteService;

	//股票代码
	@Autowired
	private ITbStockCodeService tbStockCodeService;

	

	@Override
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

		log.info(String.format(" Jeecg-Boot 普通定时任务 SampleJob !  时间:" + DateUtils.getTimestamp()));
		saveK();

	}


	public void  saveK(){

		try {
			QueryWrapper<TbStockCode> queryWrapper = new QueryWrapper<>();
			queryWrapper.eq("has_child","0");
//			queryWrapper.eq("pid","600");
//			queryWrapper.eq("code","000063");
//			queryWrapper.eq("code","600660");
			//查询所有的股票代码
			List<TbStockCode> list = tbStockCodeService.list(queryWrapper);
			for (TbStockCode tbStockCode : list) {
				String code = tbStockCode.getCode();
				tbStockKService.saveList(code);
			}

			//保存分钟
			for (TbStockCode tbStockCode : list) {
				String code = tbStockCode.getCode();
				tbStockMinuteService.saveList(code);
			}


			System.out.println("执行结束");


		} catch (ParseException e) {
			e.printStackTrace();
		}

	}
}
